<template>
  <div ref="popW">
    <div class="popContent">
      <div class="font-lan-l mb-3 d-flex ai-center">
        <img :src="camera" alt="" class="mr-2">
        <div>{{ data.name ? data.name : "暂无数据" }}</div>
      </div>
        <el-row :gutter="16">
          <el-col :span="24" class="mb-1">
            <div class="d-flex ai-center">
              <img class="mr-2" :src="locationIcon" alt="">
              <span class="description">地址：</span
              ><span class="font-lan-m">{{
                data.address ? data.address : "暂无数据"
              }}</span>
            </div>
          </el-col>
          <el-col :span="12" class="mb-2"  v-for="(item, index) in list" :key="index">
            <div class="d-flex ai-center">
              <img :src="item.img" alt="" class="mr-2">
              <div>
                <div class="font-lan-gray-60-m">{{item.name}}：</div>
                <div><span class="font-num-m">{{item.value?item.value:'-'}}</span><span class="font-lan-s">{{item.unit}}</span></div>
              </div>
            </div>
          </el-col>
        </el-row>
    </div>
  </div>
</template>

<script lang="ts">
import {
  defineComponent,
  ref,
  reactive,
  onMounted,
  onUnmounted,
  watch,
} from "vue";

// 声明类型
const PropsType = {
  data: {
    type: Object,
    default: {},
    require: true,
  },
} as const;
export default defineComponent({
  props: PropsType,
  components: {},
  setup(props) {
    //变量
    const camera = require('@/assets/img/camera.png')
    const locationIcon = require('@/assets/img/locationIcon.png')

    const list = ref([
      {name:'温度',unit:'℃',value:null,img:require('@/assets/img/weatherTem.png')},
      {name:'湿度',unit:'%',value:null,img:require('@/assets/img/weatherHum.png')},
      {name:'光照',unit:'kLx',value:null,img:require('@/assets/img/weatherSun.png')},
      {name:'雨量',unit:'mm',value:null,img:require('@/assets/img/weatherRain.png')},
      {name:'风向',unit:'向',value:null,img:require('@/assets/img/weatherDir.png')},
      {name:'风速',unit:'m/s',value:null,img:require('@/assets/img/weatherWind.png')},
    ])

    // 生命周期
    onMounted(() => {
      //
    });

    onUnmounted(() => {
      //
    });

    watch(
      () => props.data.list,
      (val: any) => {
        //
        list.value = [
        {name:'温度',unit:'℃',value:null,img:require('@/assets/img/weatherTem.png')},
        {name:'湿度',unit:'%',value:null,img:require('@/assets/img/weatherHum.png')},
        {name:'光照',unit:'kLx',value:null,img:require('@/assets/img/weatherSun.png')},
        {name:'雨量',unit:'mm',value:null,img:require('@/assets/img/weatherRain.png')},
        {name:'风向',unit:'向',value:null,img:require('@/assets/img/weatherDir.png')},
        {name:'风速',unit:'m/s',value:null,img:require('@/assets/img/weatherWind.png')},
        ]
        if(val && val.length>0){
          list.value.forEach(item=>{
            val.forEach(item1=>{
              if(item.name == item1.dataName){
                item.value = item1.dataValue
              }
            })
          })
        }
      },
      {
        immediate: true,
        deep: true,
      }
    );

    //methods
    

    // return
    return {
      camera,
      locationIcon,
      list
    };
  },
});
</script>

<style lang="scss" scoped>
@import "@/assets/scss/index.scss";
.popContent {
  color: #fff;
  .description {
    font-size: 12px;
    font-family: Alibaba-PuHuiTi-Medium, Alibaba-PuHuiTi;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.8);
    line-height: 16px;
    -webkit-background-clip: text;
  }
}
</style>
